import React, { Component } from 'react';
import { message } from 'antd';
import PropTypes from 'prop-types';
import { connect } from "dva";
import './index.less';
message.error('绿盒');
class App extends Component {
    constructor(props){
        super(props);
    }
    render(){
        const { test, onIncreaseClick, onMinutesClick, history } = this.props;
        const { value, isShow } = test;
        return (
            <div className="content-panel">
                <a onClick={() => {
                    history.push('/test');
                }}>test</a>
                <h1>{value}</h1>
                <button onClick={() => onIncreaseClick(value)}>增加</button>
                {isShow && (
                    <button onClick={() => onMinutesClick(value)}>减少</button>
                )}
            </div>
        );
    }
}

//传入参数检测
App.propTypes = {
    test: PropTypes.object,
    onIncreaseClick: PropTypes.func,
    onMinutesClick: PropTypes.func,
    history: PropTypes.object
};

const mapStateToProps = ({ test }) => ({ test });
const mapDispatchToProps = (dispatch) => {
    return {
        onIncreaseClick: () => {
            dispatch({type: 'test/increase'});
        },
        onMinutesClick: () => {
            dispatch({type: 'test/minutes'});
        }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(App);